<template>
  <div class="teacher-home">
    <el-row :gutter="20">
      <!-- 个人信息卡片 -->
      <el-col :span="8">
        <el-card class="info-card">
          <template #header>
            <div class="card-header">
              <span>个人信息</span>
              <el-button type="primary" link @click="$router.push('/teacher/profile')">
                编辑资料
              </el-button>
            </div>
          </template>
          <div class="user-info">
            <div class="info-item">
              <label>姓名：</label>
              <span>{{ authStore.user?.name }}</span>
            </div>
            <div class="info-item">
              <label>工号：</label>
              <span>{{ authStore.user?.userId }}</span>
            </div>
            <div class="info-item">
              <label>邮箱：</label>
              <span>{{ authStore.user?.email }}</span>
            </div>
          </div>
        </el-card>
      </el-col>

      <!-- 考试管理卡片 -->
      <el-col :span="16">
        <el-card>
          <template #header>
            <div class="card-header">
              <span>考试管理</span>
              <el-button type="primary" @click="$router.push('/teacher/exams/create')">
                创建考试
              </el-button>
            </div>
          </template>
          <el-table :data="examList" style="width: 100%">
            <el-table-column prop="name" label="考试名称" />
            <el-table-column prop="startTime" label="开始时间" width="180" />
            <el-table-column prop="duration" label="考试时长" width="100">
              <template #default="scope">
                {{ scope.row.duration }}分钟
              </template>
            </el-table-column>
            <el-table-column prop="status" label="状态" width="100">
              <template #default="scope">
                <el-tag :type="getStatusType(scope.row.status)">
                  {{ scope.row.status }}
                </el-tag>
              </template>
            </el-table-column>
            <el-table-column label="操作" width="200">
              <template #default="scope">
                <el-button-group>
                  <el-button
                    type="primary"
                    size="small"
                    @click="handleMonitor(scope.row)"
                  >
                    监控
                  </el-button>
                  <el-button
                    type="success"
                    size="small"
                    @click="handleViewResults(scope.row)"
                  >
                    成绩
                  </el-button>
                </el-button-group>
              </template>
            </el-table-column>
          </el-table>
        </el-card>
      </el-col>

      <!-- 试题管理 -->
      <el-col :span="12" style="margin-top: 20px;">
        <el-card>
          <template #header>
            <div class="card-header">
              <span>试题管理</span>
              <el-button type="primary" link @click="$router.push('/teacher/questions')">
                管理试题
              </el-button>
            </div>
          </template>
          <el-row :gutter="20">
            <el-col :span="8">
              <div class="stat-card">
                <div class="stat-value">{{ stats.totalQuestions }}</div>
                <div class="stat-label">试题总数</div>
              </div>
            </el-col>
            <el-col :span="8">
              <div class="stat-card">
                <div class="stat-value">{{ stats.categories }}</div>
                <div class="stat-label">试题分类</div>
              </div>
            </el-col>
            <el-col :span="8">
              <div class="stat-card">
                <div class="stat-value">{{ stats.usedCount }}</div>
                <div class="stat-label">使用次数</div>
              </div>
            </el-col>
          </el-row>
        </el-card>
      </el-col>

      <!-- 待办事项 -->
      <el-col :span="12" style="margin-top: 20px;">
        <el-card>
          <template #header>
            <div class="card-header">
              <span>待办事项</span>
            </div>
          </template>
          <el-timeline>
            <el-timeline-item
              v-for="todo in todos"
              :key="todo.id"
              :type="todo.type"
              :timestamp="todo.time"
            >
              {{ todo.content }}
            </el-timeline-item>
          </el-timeline>
        </el-card>
      </el-col>
    </el-row>
  </div>
</template>

<script setup>
import { ref, reactive } from 'vue'
import { useRouter } from 'vue-router'
import { useAuthStore } from '@/stores/auth'

const router = useRouter()
const authStore = useAuthStore()

// 考试列表数据
const examList = ref([
  {
    id: 1,
    name: 'C语言期中考试',
    startTime: '2024-04-01 14:00',
    duration: 120,
    status: '进行中'
  },
  {
    id: 2,
    name: 'C语言章节测试-指针',
    startTime: '2024-04-05 10:00',
    duration: 60,
    status: '未开始'
  }
])

// 统计数据
const stats = reactive({
  totalQuestions: 300,
  categories: 12,
  usedCount: 156
})

// 待办事项
const todos = ref([
  {
    id: 1,
    content: '批改C语言期中考试试卷（25份）',
    time: '2024-04-01',
    type: 'warning'
  },
  {
    id: 2,
    content: '准备下周考试试题',
    time: '2024-04-03',
    type: 'info'
  }
])

const getStatusType = (status) => {
  const typeMap = {
    '未开始': 'info',
    '进行中': 'warning',
    '已结束': ''
  }
  return typeMap[status]
}

const handleMonitor = (exam) => {
  router.push(`/teacher/monitor/${exam.id}`)
}

const handleViewResults = (exam) => {
  router.push(`/teacher/results/${exam.id}`)
}
</script>

<style scoped>
.teacher-home {
  padding: 20px;
}

.card-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.user-info {
  padding: 10px;
}

.info-item {
  margin-bottom: 15px;
  display: flex;
  align-items: center;
}

.info-item label {
  width: 60px;
  color: #909399;
}

.stat-card {
  text-align: center;
  padding: 20px;
  background-color: #f5f7fa;
  border-radius: 4px;
}

.stat-value {
  font-size: 24px;
  font-weight: bold;
  color: #409EFF;
  margin-bottom: 10px;
}

.stat-label {
  color: #909399;
  font-size: 14px;
}
</style> 